/**
 * Created by ybzc on 2017/8/30.
 */
$(function () {
    var modal_confirm = $("#confirm");
    var modal_fail = $("#fail");
    var modal_success = $("#success");
    var modal_warning = $("#warning");
    var modal_loading = $("#loading");
    var modal_upload_box = $("#upload_box");
//...后期扩展，可以继续在下面写，同时在tip.html模板里也要有对应的DIV
    var modal = {
        confirm: function (message, type) {
            modal_confirm.find('.modal-info').html(message);
            if (type == '') {
                modal_confirm.find('.modal-body i').hide();
            } else if (type == 'success') {
                modal_confirm.find('.modal-body i').removeClass().addClass('fa fa-check-circle');
            } else if (type == 'error') {
                modal_confirm.find('.modal-body i').removeClass().addClass('glyphicon glyphicon-remove-circle');
            }
            modal_confirm.modal('show');
            return {
                on: function (callback) {
                    if (callback && callback instanceof Function) {
                        modal_confirm.find('.ok').click(function () {
                            callback(true);
                        });
                    }
                }
            };
        },

        loading: function (message, type) {
            modal_loading.find('.modal-info').html(message);
            if (type == '') {
                modal_loading.find('.modal-body i').hide();
            } else if (type == 'success') {
                modal_loading.find('.modal-body i').removeClass().addClass('fa fa-check-circle');
            } else if (type == 'error') {
                modal_loading.find('.modal-body i').removeClass().addClass('glyphicon glyphicon-remove-circle');
            }
            modal_loading.modal('show');
            return {
                on: function (callback) {
                    if (callback && callback instanceof Function) {
                        modal_loading.find('.ok').click(function () {
                            callback(true);
                        });
                    }
                }
            };
        },

        upload_box: function (message, type) {
            modal_upload_box.find('.modal-info').html(message);
            if (type == '') {
                modal_upload_box.find('.modal-body i').hide();
            } else if (type == 'success') {
                modal_upload_box.find('.modal-body i').removeClass().addClass('fa fa-check-circle');
            } else if (type == 'error') {
                modal_upload_box.find('.modal-body i').removeClass().addClass('glyphicon glyphicon-remove-circle');
            }
            modal_upload_box.modal('show');
            return {
                on: function (callback) {
                    if (callback && callback instanceof Function) {
                        modal_upload_box.find('.ok').click(function () {
                            callback(true);
                        });
                    }
                }
            };
        },
    };
});

